package com.aaa.controller;

import com.aaa.pojo.EmpSalary;
import com.aaa.pojo.Employee;
import com.aaa.service.EmployeeService;
import com.aaa.utils.RespBean;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author bSu
 * @date 2020/6/3 - 16:22
 */
@RestController
@RequestMapping("/employee")//工资管理_员工账套
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    //联合分页查询所有
    @GetMapping("/all")
    public RespBean getAll(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        RespBean respBean=RespBean.build();
        PageInfo<Employee> allEmployeeByPage = employeeService.getAllEmployeeByPage(pageNum, pageSize);
        respBean.setStatus(200);
        respBean.setMsg("查询成功");
        respBean.setObj(allEmployeeByPage);

        return respBean;
    }

    //员工账套竟然只有查询和修改，话说批量修改就麻烦前端宇哥哥多次提交了，这就不in了
    @PostMapping("/update")
    public RespBean update(EmpSalary empSalary){
        RespBean respBean=RespBean.build();
        respBean.setStatus(100);
        if(empSalary.getEid()==null||empSalary.getSid()==null){
            respBean.setMsg("参数不能为空");
            return respBean;
        }
        int i = employeeService.updateEmployeeSalaryById(empSalary);
        System.out.println(i);
        if(i<=0){
            respBean.setMsg("修改失败");
            return respBean;
        }
        respBean.setStatus(200);
        respBean.setMsg("修改成功");
        return respBean;
    }

}
